import Taro, {Component, Config} from '@tarojs/taro'
import { View } from '@tarojs/components'
import './index.scss'
import { getByOrderIdPage } from '@/api/commentApi'
import { Loading } from '@/components/index'
import CommentItem from '@/components/comment/comment-item/index'

export default class Index extends Component {
  state: any
  config: Config = {
    backgroundTextStyle: "dark",
    navigationBarTitleText: '评论列表'
  }

  constructor() {
    super(...arguments)
    const { params: { id } } = this.$router
    this.state = {
      id,
      loading: true,
      dataList: []
    }
  }

  componentWillMount() {
    this.getPage()
  }

  //  分页获取评论
  getPage() {
    getByOrderIdPage(this.state.id).then(({ data }) => {
      this.setState({
        dataList: data,
      }, () => {
        this.setState({
          loading: false,
        })
      })
    })
  }

  render() {
    const { dataList, loading } = this.state
    return (<View className='comment-page'>
      {loading && <Loading/>}
      <View className='newest-list'>
        {dataList.map(item => {
          return (<CommentItem key={item.id} info={item} className='newest-item' showGoods/>)
        })}
      </View>
    </View>)
  }
}
